
<template>
  <div>
    <Card ref="card">
      <p slot="title">新增人员汇总</p>
      <Row :gutter="16">
        <Col span="6">
          <Input v-model="pName" size="large" placeholder="姓名/身份证号/住址" />
        </Col>

        <Col span="4">
          <Button @click="Search" size="large" type="primary" icon="ios-search">查询</Button>
        </Col>
      </Row>
    </Card>
    <Modal :mask-closable="false" v-model="modal2" width="500">
      <p slot="header" class="color-primary text-align-center">
        <Icon type="ios-information-circle"></Icon>
        <span>转移到项目</span>
      </p>

      <br />

      <Row>
        <Select
          filterable
          label-in-value
          @on-change="perChange"
          v-model="grouptmp"
          size="large"
          placeholder="请选择项目"
        >
          <Option v-for="item in grouplist" :value="item.Gid" :key="item.Gid">{{ item.GroupName }}</Option>
        </Select>
      </Row>
      <br />
      <Row>
        <Input v-model="personTemp.GroupTown" size="large" placeholder="所属乡镇" />
      </Row>
      <br />
      <Button
        size="large"
        @click="personTemp.GroupTown=item.TownName"
        v-bind:key="item.Id"
        v-for="item in townList"
        style="margin-left:5px;margin-bottom:5px"
      >{{ item.TownName }}</Button>

      <br />
      <div slot="footer">
        <Button type="primary" size="large" v-on:click="TransPersonGroup">保存</Button>
      </div>
    </Modal>
    <Row class="margin-top-10">
      <Table border :columns="tableTitle" :data="tableData" ref="table" :height="tableHeight"></Table>
    </Row>
    <Row class="margin-top-10">
      <Page
        :total="total"
        :current="pPage"
        :page-size="pSize"
        :page-size-opts="[50,100,300,500,1000,2000,5000]"
        @on-change="s=>{pPage=s;Search();}"
        @on-page-size-change="p=>{pSize=p;pPage=1;Search()}"
        show-total
        show-sizer
      />
    </Row>
  </div>
</template>
<script>
import { Message, Modal } from "view-design";
import {
  SearchPerson,
  DeletePerson,
  TransPersonGroup,
  SearchPersonGroup,
  GetGroupTown
} from "@/api/data";
export default {
  name: "search_person_new",
  data() {
    return {
      tableHeight: 450,
      total: 0,
      pPage: 1,
      pSize: 50,
      modal2: false,
      personTemp: {},
      grouplist: [],
      townList: [],
      grouptmp: "",
      grouptid: "",
      grouptname: "",
      tableTitle: [
        {
          title: "序号",
          key: "R_INDEX",
          align: "center",
          width: 80
        },
        {
          title: "操作",
          key: "action",
          width: 160,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.personTemp = params.row;
                      this.modal2 = true;
                    }
                  }
                },
                "转移到项目"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.DeletePerson(params.row.Gid);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        },
        {
          title: "姓名",
          key: "Name",
          align: "center",
          width: 80
        },
        {
          title: "性别",
          key: "Sex",
          align: "center",
          width: 80
        },
        {
          title: "供养类型",
          key: "SupportType",
          align: "center",
          width: 80,
          render: (h, params) => {
            if (params.row.SupportType == 1) {
              return h(
                "Tag",
                {
                  props: {
                    color: "success"
                  }
                },
                "集中"
              );
            }else  if (params.row.SupportType == 2) {
              return h(
                "Tag",
                {
                  props: {
                    color: "primary"
                  }
                },
                "分散"
              );
            }
          }
        },
        {
          title: "户籍地",
          key: "BirthAddress",
          align: "center",
          width: 100
        },
        {
          title: "住址",
          key: "Address",
           align: "center",
          minWidth:120
        },
        {
          title: "身份证号",
          key: "IdCard",
          align: "center",
          minWidth:160
        },
        {
          title: "评估类型",
          key: "AssessType",
          align: "center",
          width: 80,
          render: (h, params) => {
            if (params.row.AssessInfo != null) {
              if (params.row.AssessInfo.AssessType == 1) {
                return h("div", "标准");
              } else if (params.row.AssessInfo.AssessType == 2) {
                return h("div", "标准(新)");
              } else if (params.row.AssessInfo.AssessType == 3||params.row.AssessInfo.AssessType == 4) {
                return h("div", "特困");
              } else {
                return h("div", "简易");
              }
            }
          }
        },
        {
          title: "状态",
          align: "center",
          key: "FinalState",
          width: 80,
          render: (h, rparams) => {
            if (rparams.row.FinalState == null) {
              return h(
                "Tag",
                {
                  props: {
                    color: "default"
                  }
                },
                "待评估"
              );
            } else {
              var ctype = "default";
              if (
                rparams.row.FinalState == "重度失能" ||
                rparams.row.FinalState == "失能"
              ) {
                ctype = "error";
              } else if (
                rparams.row.FinalState == "中度失能" ||
                rparams.row.FinalState == "半自理"
              ) {
                ctype = "warning";
              } else if (rparams.row.FinalState == "轻度失能") {
                ctype = "primary";
              } else if (
                rparams.row.FinalState == "能力完好" ||
                 rparams.row.FinalState == "自理"|| rparams.row.FinalState == "自理"
              ) {
                ctype = "success";
              }
              return h(
                "Button",
                {
                  props: {
                    type: ctype,
                    size: "small"
                  },
                  on: {
                    click: () => {
                      //简易评估
                      if (rparams.row.AssessInfo.AssessType == 0) {
                        this.$router.push({
                          name: "assess_info",
                          params: { id: rparams.row.Gid }
                        });
                      }
                      //标准评估
                      else if (rparams.row.AssessInfo.AssessType == 1) {
                        this.$router.push({
                          name: "standard_assess_info",
                          params: { id: rparams.row.Gid }
                        });
                      }//新标准评估
                      else if (rparams.row.AssessInfo.AssessType == 2) {
                          this.$router.push({
                            name: "assess_new_info",
                            params: { id: rparams.row.Gid }
                          });
                        }  //特困评估
                      else if (rparams.row.AssessInfo.AssessType == 3) {
                        this.$router.push({
                          name: "tekun_assess_info",
                          params: { id: rparams.row.Gid }
                        });
                      } //新特困评估
                      else if (rparams.row.AssessInfo.AssessType == 4) {
                        this.$router.push({
                          name: "tekun_new_assess_info",
                          params: { id: rparams.row.Gid }
                        });
                      }
                    }
                  }
                },
                rparams.row.FinalState
              );
            }
          }
        },
        {
          title: "备注",
          key: "Remark",
          render: (h, params) => {
            if (params.row.AssessInfo == null) {
              return h();
            } else {
              return h("div", params.row.AssessInfo.Remark);
            }
          }
        }
      ],
      tableData: [],
      pName: ""
    };
  },
  methods: {
    perChange(e) {
      this.grouptid = e.value;
      this.grouptname = e.label;
      this.GetGroupTown(this.grouptid);
    },
    TransPersonGroup() {
      let vm = this;
      if (!vm.grouptid) {
        this.$Modal.error({ title: "提示", content: "请选择项目" });
        return;
      }
      if (!vm.personTemp.GroupTown) {
        this.$Modal.error({ title: "提示", content: "请选择乡镇" });
        return;
      }
      
      var reqData = {
        groupid: vm.grouptid,
        groupname: vm.grouptname,
        grouptown: vm.personTemp.GroupTown,
        personid: vm.personTemp.Gid
      }; 
      TransPersonGroup(reqData).then(res => {
        const data = res.data;
        if (data.Type == 1) {
          vm.modal2 = false;
          this.Search();
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    SearchPersonGroup() {
      let vm = this;
      var reqData = {
        issaved: 0
      };
      SearchPersonGroup(reqData).then(res => {
        const data = res.data;
        if (data.Type == 1) {
          vm.grouplist = data.Data;
        } else {
          vm.$Message.error(data.Message);
        }
      });
    },
    GetGroupTown(groupid) {
      let vm = this;
      GetGroupTown(groupid).then(res => {
        const data = res.data;
        if (data.Type == 1) {
          vm.townList = data.Data;
          console.log(vm.townList);
        } else {
        }
      });
    },
    DeletePerson(id) {
      this.$Modal.confirm({
        title: "提示",
        content: "确定要删除此评估人员吗？",
        onOk: () => {
          DeletePerson(id).then(res => {
            const data = res.data;
            if (data.Type == 1) {
              this.Search();
              this.$Modal.success({ title: "提示", content: "删除成功" });
            } else {
              this.$Modal.error({ title: "提示", content: data.Message });
            }
          });
        },
        onCancel: () => {}
      });
    },
    Search() {
      let vm = this;
      var reqData = {
        page: vm.pPage,
        size: vm.pSize,
        groupid: "A07606F6-BAEB-493F-A3C7-8E2C6525DF91",
        state: 1,
        str: vm.pName
      };
      SearchPerson(reqData).then(res => {
        const data = res.data;
        if (data.Type == 1) {
          vm.total = data.Data.Total;
          vm.tableData = data.Data.Rows;
        } else {
          Message.error(data.Message);
        }
      });
    }
  },
  created() {},
  mounted() {
    var cardHeight = this.$refs.card.$el.offsetHeight;
    this.tableHeight = window.innerHeight - cardHeight - 200;
    this.Search();
    this.SearchPersonGroup();
  }
};
</script>
